//
//  VCOfQuestionsAndAnswersAuslese.m
//  LCOnePsychology
//
//  Created by li cheng on 16/9/6.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "VCOfQuestionsAndAnswersAuslese.h"
#import "BaseTableView.h"
#import "MJMacro.h"
#import "TVCellOfQuestionsAndAnswersAuslese.h"
#import "DataOfQuestionsAndAnswersAuslese.h"
#import "ListOfDataQuestionsAndAnswersAuslese.h"
#import "MsgOfDataQuestionsAndAnswersAuslese.h"
#import "RootClassOfQuestionsAndAnswersAuslese.h"
#import "ZWYNetTool.h"
#import "UIImageView+WebCache.h"
@interface VCOfQuestionsAndAnswersAuslese ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) RootClassOfQuestionsAndAnswersAuslese *rootClassOfQuestionsAndAnswersAuslese;
@property (nonatomic, strong) BaseTableView *tableViewOfQuestionsAndAnswersAuslese;
@end

@implementation VCOfQuestionsAndAnswersAuslese

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"问答精选集";
    // 数据处理
    [self handleData];
    // 创建 tableView
    [self createTableView];
}
#pragma mark - 数据处理
- (void)handleData{
    [ZWYNetTool POST:@"http://yiapi.xinli001.com/v2/yi/get-qa-disabuse.json" andBody:@"offset=0&limit=20&key=e110509c8317557ef50ce777d107f4b3&v=1&_platform=android&sign=cddf6a97eebb6e628269a52d8ac05e86&_version=4.0&token=0d4eeb8732f9ae2c73401002570ceb93" andBodyStyle:ZWYBodyString andHeader:nil andResponse:ZWYJSON andSuccessBlock:^(id result) {
        _rootClassOfQuestionsAndAnswersAuslese = [RootClassOfQuestionsAndAnswersAuslese modelDic:result];
        [self.tableViewOfQuestionsAndAnswersAuslese reloadData];
    } andFailureBlock:^(NSError *error) {
        
    }];
}
#pragma mark 创建 tableView
- (void)createTableView{
    self.tableViewOfQuestionsAndAnswersAuslese = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49) style:UITableViewStylePlain];
    self.tableViewOfQuestionsAndAnswersAuslese.backgroundColor = [UIColor colorWithWhite:0.937 alpha:1.000];
    [self.view addSubview:_tableViewOfQuestionsAndAnswersAuslese];
    self.tableViewOfQuestionsAndAnswersAuslese.delegate = self;
    self.tableViewOfQuestionsAndAnswersAuslese.dataSource = self;
    [self.tableViewOfQuestionsAndAnswersAuslese registerNib:[UINib nibWithNibName:@"TVCellOfQuestionsAndAnswersAuslese" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"TVCellOfQuestionsAndAnswersAuslese"];
}
#pragma mark - tableView 代理方法 row 数量的确定
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
#pragma mark - tableView 代理方法 row 高度的确定
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return SCREEN_HEIGHT / 3;
}
#pragma mark - tableView 代理方法 cell 的赋值
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TVCellOfQuestionsAndAnswersAuslese *cell = [tableView dequeueReusableCellWithIdentifier:@"TVCellOfQuestionsAndAnswersAuslese" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor colorWithWhite:0.937 alpha:1.000];
    [cell.imageImageView sd_setImageWithURL:[NSURL URLWithString:_rootClassOfQuestionsAndAnswersAuslese.data.list[indexPath.row].image] placeholderImage:[UIImage imageNamed:@"JustAMoment"]];
    cell.imageImageView.layer.cornerRadius = 10;
    cell.imageImageView.clipsToBounds = YES;
    cell.titleLabel.text = _rootClassOfQuestionsAndAnswersAuslese.data.list[indexPath.row].title;
    cell.publishLabel.text = [NSString stringWithFormat:@"%@期", _rootClassOfQuestionsAndAnswersAuslese.data.list[indexPath.row].publish];
    cell.view_numLabel.text = _rootClassOfQuestionsAndAnswersAuslese.data.list[indexPath.row].view_num;
    cell.comment_numLabel.text = _rootClassOfQuestionsAndAnswersAuslese.data.list[indexPath.row].comment_num;
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
